package com.markerhub.controller;

import com.markerhub.common.lang.Result;
import com.markerhub.handler.Back_token_Auth;
import com.markerhub.service.CabinetService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Author by MaXiaofeng
 * @Description 外卖柜controller
 * @Date 2022/2/22 21:01
 * @Version 1.0.0
 */
@Slf4j
@RestController
@RequestMapping("/cabinet")
public class CabinetController {
    @Autowired
    private CabinetService cabinetService;

    /**
     * 根据省市区级别等条件查询外卖柜信息
     *
     * @param jsonBody
     * @return
     */
    @Back_token_Auth
    @PostMapping("findCabinetId")
    public Result findCabinetIdByCondition(@RequestBody Map<String, String> jsonBody) {
        Result result = cabinetService.findCabinetIdByCondition(jsonBody);
        log.info("{}", result);
        return result;
    }

    /**
     * 根据外卖柜的id信息获取该外卖柜的所有柜门订单情况
     *
     * @param jsonBody
     * @return
     */
    @Back_token_Auth
    @PostMapping("findCabinetSituation")
    public Result findCabinetSituation(@RequestBody Map<String, String> jsonBody) {
        String cabinet_id = jsonBody.get("cabinet_id");
//        if (cabinet_id == null) return Result.fail("请上传接口要求的参数");
        int cabinetId = Integer.parseInt(cabinet_id);
        Result result = cabinetService.findCabinetSituation(cabinetId);
        log.info("{}", result);
        return result;
    }
}
